package simul;

import data.obj.CombatResult;
import data.obj.CriticalResult;
import util.Dice;

public class Character
{
	double attachAttitude;

	double ob;
	double db;

	double hit;
	double endurance;
	double actualOB;
	double acutalDB;
	int at;
	int weapon;
	CombatResult charactercombatResult = new CombatResult();
	

	public Character(double attachAttitude, int ob, int db, double hit, double endurance, int at, int weapon )
	{
		super();
		this.attachAttitude = attachAttitude;
		this.ob = ob;
		this.db = db;
		this.hit = hit;
		this.endurance = endurance;
		this.at=at;
		this.weapon=weapon;

	}

	public boolean isDead()
	{
		if( hit <= charactercombatResult.getHit())
			return true;
		if( endurance <= charactercombatResult.getEndurance())
			return true;
		if(charactercombatResult.getCriticalResult().isDeath())
			return true;
		return false;
	}

	public boolean isExahusted()
	{
		return endurance <= 0;
	}

	public void calculateAcutalDB()
	{
		// percentage ob +/- 10%
		actualOB = Math.floor(ob * (attachAttitude * (1 + 1 / (1 + Dice.DNNN(99)))));
		if (actualOB > ob)
			actualOB = ob;
		if (actualOB < 0)
			actualOB = 0;
		acutalDB = ob - actualOB+db;
	}

	@Override
    public String toString()
    {
	    return "Character [attachAttitude=" + attachAttitude + ", ob=" + ob + ", db=" + db + ", hit=" + hit + ", endurance=" + endurance + ", at=" + at
	            + ", weapon=" + weapon + "]";
    }

	public void calculateResultCombat(CombatResult cRes)
    {
		charactercombatResult.add(cRes);
	    charactercombatResult.setEndurance(charactercombatResult.getEndurance()+2);
	    nextTurn();
    }

	private void nextTurn()
    {
		charactercombatResult.setHit(charactercombatResult.getHit()+charactercombatResult.getCriticalResult().getHitRound());
		//aggiungere controllo stato: 
		must parry
		stunned
		unable to parry
		e conteggiare penality
	    
    }
	
	

}
